<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/12 0012
 * Time: 下午 3:57
 */
namespace app\api\controller;

use app\common\lib\Qiniu;

class Image extends Base {
    public function upload(){

        if (empty($_FILES['file'])) {
            return show(config('status.ERROR_STATUS'), '您提交的图片数据不合法', '您提交的图片数据不合法');
        }
        $Qiniu = new Qiniu();

        $upload = $Qiniu->postDoupload($_FILES['file']);

        if($upload['status'] == 'fail'){
            return show(config('status.ERROR_STATUS'), $upload['message'], $upload['message']);
        }

        $imgurl = config('qiniu.image_url') . $upload['key'];


        return show(config('status.SUCCESS_STATUS'), 'ok', $imgurl);

    }

    public function uploadstream($data){
        $Qiniu = new Qiniu();
        $upload = $Qiniu->ResumeUpload($data);
        if($upload['status'] == 'fail'){
            return show(config('status.ERROR_STATUS'), $upload['message'], $upload['message']);
        }
        $imgurl = config('qiniu.image_url') . $upload['key'];


        return $imgurl;

    }
}